package sortmodule;

import java.util.Arrays;

/**
 * @author by 何坤
 * @Classname BubbleSort
 * @Description 冒泡排序
 * @Date 2019/10/18 17:42
 */
public class BubbleSort {
    public static void main(String[] args) {
        int[] ints = {6,1,9,2,78,45,91,45,26,11,15};
        sort(ints);
        Arrays.stream(ints).forEach(System.out::println);
    }

    private static void sort(int[] arr){
        if (arr == null && arr.length == 0){
            return;
        }
        int n = arr.length;
        for (int i = 0; i < n-1; i++){
            boolean flag = true;
            for (int j = 0; j < n - i - 1; j++){
                if (arr[j] > arr[j+1]){
                    int temp = arr[j];
                    arr[j] = arr[j+1];
                    arr[j+1] = temp;
                    flag = false;
                }
            }
            if (flag){
                return;
            }
        }
    }
}
